var msr = "";
var shxy = "";
$(function () {
    $("#search").show();
    $("#form_search").on("submit", function (e) {
        e.preventDefault();
        $("#tptj").hide();
        search();
        return false;
    });
    $("#sexr_nav a").on("click", function () {
        if ($(this).data("lx") == "1") {
            if ($("#s_name").data("lx") == "0") {
                shxy = $("#s_name").val();
                $("#s_name").val(msr);
            }
            $("#s_name").data("lx", "1");
            $("#s_name").attr("placeholder", "请输入您要查询的纳税人名称");
        } else {
            if ($("#s_name").data("lx") == "1") {
                msr = $("#s_name").val();
                $("#s_name").val(shxy);
            }
            $("#s_name").data("lx", "0");
            $("#s_name").attr("placeholder", "请输入您要查询的社会信用代码");
        }
    });
});

function search() {
    ajsear({curr: 1}, true);
}

function pageView(obj) {
    ajsear(obj, false);
}

function ajsear(obj, isfit) {

    var lx = $("#sexr_nav .active a");
    var n = $("#s_name").val();
    if (n == "") {
        layer.alert("请填写查询内容！");
        return;
    }
    var lay = layer.load({shade: [0.1]});
    $.ajax({
        url: ctx + "/mge/adx/syfx/qyhx/queryQyxx?pageNumber=" + obj.curr + "&pageSize=12&sd3=" + lx.attr("data-lx"),
        data: $("#form_search").formSerialize(),
        type: "post",
        dataType: "json",
        success: function (data, sta) {
            layer.close(lay);
            if (data != null && data.code == "200") {
                $("#content").html("");
                if (isfit) {
                    $("#searhcont").css("top", "260px");
                    $("#imgv").hide();
                    rowd(data, true);
                } else {
                    rowd(data, false);
                }
                $('.postip').poshytip();
            } else {
                layer.alert(data.message);
            }
        },
        error: function (sta) {
            layer.close(lay);
        }
    })
}

function rowd(data, isp) {
    $("#searhcont").show();
    var rows = data.rows;
    if (data.total <= 0) {
        $("#content").html("<center>未找到符合条件的企业</center>");
    }
    if (rows.length > 0) {
        cdli(rows);
        if (isp) {
            laypage({
                cont: 'page',
                pages: data.pages,
                curr: data.page,
                jump: function (obj, firs) {
                    if (!firs) {
                        pageView(obj);
                    }
                }
            });
        }
    }
}

function cdli(rows) {
    for (var i in rows) {
        var row = rows[i];
        var p = '<div class="md-4" style="cursor: pointer" onclick="oplct(\'' + row.djxh + '\',\'' + row.mlDm + '\',\'' + row.nsrmc + '\')"> <div class="tile-container"> <div class="tile-title"> <h3> ' +
            '<a href="javascript:;" class="postip" style="color: #e69024"  title="' + row.nsrmc + '" >' + cmm.strLen(row.nsrmc, 16) + '</a>  </h3>' +
            ' <div class="tile-desc">' +
            '<p>社会信用代码： <span class="postip"  title="' + vns(row.shxydm) + '">' + cmm.strLen(row.shxydm, 15) + '</span> <span  class="ml-15">法定代表人：' + vns(row.fddbrxm) + '</span></p> ' +
            ' <p>主营行业： <span class="postip" title="' + vns(row.hyxl) + '">' + cmm.strLen(vns(row.hyxl), 6) + '</span> <span class="ml-15 postip" title="' + vns(row.djzclx) + '">登记注册类型：' + cmm.strLen(vns(row.djzclx), 6) + '</span></p> ' +
            '<p>注册地址：<span class="postip" title="' + vns(row.zcdz) + '">' + cmm.strLen(vns(row.zcdz), 16) + '</span></p>' +
            ' </div> </div> </div> </div>';
        $("#content").append(p);
    }
}

var uuid = cmm.uuid();

function oplct(djxh, ml, nsrmc) {
    window.parent.openMenuDataId(ctx + '/mge/adx/qyhx/qygm?djxh=' + djxh + "&ml=" + ml, uuid, "企业概貌", true);
}

function vns(v) {
    if (v != null) {
        return v;
    }
    return "-";
}